// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db = cloud.database()

// 云函数入口函数
exports.main = async (event, context) => {
  console.log(event)
  try {
    await db.collection('class').doc('inc_id').update({
      data: {
        count: db.command.inc(1)
      }
    })

    let id = await db.collection('class').doc('inc_id').get()

    console.log(id)
    return await db.collection('class').add({
      data: {
        userId: event.userInfo.openId,
        name: event.name,
        desc: event.desc,
        no: id.data.count
      }
    })
  } catch (e) {
    console.log(e)
  }
}